package com.own.demo.lwf.utils.workUtils;

import java.util.Calendar;
import java.util.Date;
import java.util.regex.Pattern;

public class SzTrtUtil {
    //查询时间上月
    public static String beforQueryDate(Date queryDate){
        Calendar calendar = Calendar.getInstance();//日历对象
        calendar.setTime(queryDate);//设置当前日期
        calendar.add(Calendar.MONTH, -1);//月份减一
        String date = DateUtil.date2Str(calendar.getTime(),"yyyyMM");
        String d = Integer.toString(SzTrtUtil.numString(date));
        return d;
    }
    //查询时间上天
    public static String beforDays(Date queryDate){
        Calendar calendar = Calendar.getInstance();//日历对象
        calendar.setTime(queryDate);//设置当前日期
        calendar.add(Calendar.DATE, -1);//日减一
        String date = DateUtil.date2Str(calendar.getTime(),"yyyy-MM-dd");
        return date;
    }
    //查询时间上天
    public static String afterMonth(Date queryDate,int num){
        Calendar calendar = Calendar.getInstance();//日历对象
        calendar.setTime(queryDate);//设置当前日期
        calendar.add(Calendar.MONTH, + num);//月份加
        String date = DateUtil.date2Str(calendar.getTime(),"yyyy-MM-dd");
        return date;
    }
    public static String afterQueryMonth(Date queryDate,int num){
        Calendar calendar = Calendar.getInstance();//日历对象
        calendar.setTime(queryDate);//设置当前日期
        calendar.add(Calendar.MONTH, + num);//月份加
        String date = DateUtil.date2Str(calendar.getTime(),"yyyyMM");
        return date;
    }
    //字符串中保留数字,并转换整形
    public static int numString(String s){
        String REGEX = "[^0-9]";
        String ticket = Pattern.compile(REGEX).matcher(s).replaceAll("").trim();
        int t = Integer.parseInt(ticket);
        return t;
    }
}